/*
 * AqueousSolution.h
 *
 *  Created on: 1 Aug 2011
 *      Author: Allan
 */

#ifndef AQUEOUSSOLUTION_H_
#define AQUEOUSSOLUTION_H_

// GeoReact includes
#include "Activity/AqueousActivity.h"
#include "Solution.h"
#include "Utils.h"

class AqueousSolution : public Solution
{
public:
	AqueousSolution();
	
	explicit AqueousSolution(const vector<string>& species);
	
	virtual ~AqueousSolution();
	
	void
	SetActivityModel(const string& species, const AqueousActivityModel& model);
	
	virtual const string
	GetName() const;
	
	virtual const vector<string>
	GetSpecies() const;
	
	const vector<string>
	GetIonicSpecies() const;
	
	const VectorXd
	GetIonicCharges() const;
	
	const Index
	GetWaterIndex() const;
	
	const VectorXd
	Molalities(const VectorXd& n) const;
	
	virtual const VectorXd
	MolarFractions(const VectorXd& n) const;
	
	virtual const VectorXd
	Concentrations(const VectorXd& n) const;
	
	virtual const VectorXd
	ActivityCoefficients(double T, double P, const VectorXd& n) const;
	
	virtual const VectorXd
	Activities(double T, double P, const VectorXd& n) const;
	
	const double
	IonicStrengthEffective(const VectorXd& n) const;
	
	const double
	IonicStrengthStoichiometric(const VectorXd& n) const;
	
	const VectorXd
	IonicMolalities(const VectorXd& n) const;
	
	const VectorXd
	IonicMolalitiesStoichiometric(const VectorXd& n) const;
	
private:
	/// The species in the aqueous solution
	vector<string> species;
	
	/// The index of the water species
	Index iwater;
	
	/// The vector of electrical charges of the ionic species
	VectorXd zi;
	
	/// The indexes of the ions and complexes
	vector<Index> ions, complexes;
	
	/// The stoichiometric matrix between the complexes and ions
	MatrixXd vei;
	
	/// The activity coefficient function of each aqueous species
	vector<AqueousActivityModel> activityCoeffFunctions;
	
private:
	void 
	InitializeActivityModels();
	
	void 
	InitializeComplexes();
};

#endif /* AQUEOUSSOLUTION_H_ */
